﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Table_Dal;
namespace DAL
{
    public class ChitietdethiDAL:DataAccessLayer
    {
        DataDataContext dt;
        public bool XoaTatca_Madethi(string Madethi)
        {
            try
            {
                dt = GetKetnoi();
                IEnumerable<CHITIETDETHI> q = dt.CHITIETDETHIs.Where(j=>j.MADETHI ==Madethi);
                dt.CHITIETDETHIs.DeleteAllOnSubmit(q);
                dt.SubmitChanges();
            }
            catch
            {
                return false;
            }
            return true;
        }
        public List<CauhoiThi> Laydanhsachcauhoi(string Made)
        {
            dt = GetKetnoi();
            IEnumerable<CAUHOI> q = from i in dt.CAUHOIs
                                    join j in dt.CHITIETDETHIs
                                    on i.MACAUHOI equals j.MACAUHOI
                                    where j.MADETHI == Made
                                    select i;
            List<CauhoiThi> ds = new List<CauhoiThi>();
            foreach (CAUHOI item in q)
            {
                CauhoiThi ch = new CauhoiThi();
                ch.MaCauHoi = item.MACAUHOI;
                ch.NoiDung = item.NOIDUNG;
                ch.HinhAnh = item.HINHANH;
                ch.Flag = 0;
                DapAnDal da = new DapAnDal();
                ch.SoDapAnDung = da.TongSoDapAnDung(ch.MaCauHoi);
                ds.Add(ch);
            }
            return ds;
        }
        public bool ThemChiTietDethi(ChiTietDethiTbl chitiet)
        {
            dt = GetKetnoi();
            CHITIETDETHI ctch = new CHITIETDETHI();
            ctch.MACAUHOI = chitiet.MACAUHOI;
            ctch.MADETHI = chitiet.MADETHI;
            dt.CHITIETDETHIs.InsertOnSubmit(ctch);
            dt.SubmitChanges();
            return true;
        }
    }
}
